<%@page contentType="text/html; charset=UTF-8" %>
<jsp:useBean id="user" class="entity_beans.User" scope="session"></jsp:useBean>
<jsp:useBean id="auxBean" class="model.AuxBean" scope="request"></jsp:useBean>

<%@page import="entity_beans.Flight" %>
<%@page import="utils.DateTest"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Air Transport - Main Page</title>
</head>
<body>
<%
	if (user.isAccessed() == false) {
		response.sendRedirect("../index.jsp");
		return;
	}

	if ( user.isLoggedIn() == false ) {
		response.sendRedirect("../index.jsp");
		return;
	}
%>



<h2><u>Air Transport Service - Main Page</u></h2>

<jsp:include page="header.jsp"></jsp:include>

<%
	if (auxBean.getFlights().size() != 0) {
%>

Flights: <br>
	<table border="1">
		<tr bgcolor="lightgrey">
			<th>No</th>
			<th>Flight ID</th>
			<th>Deparutre Time</th>
			<th>Arrival Time</th>
			<th>Source</th>
			<th>Destination</th>
			<th>Reserved Seats</th>
			<th>Reservation</th>
		</tr>
<%
	String bgColor = "#99CCFF";

	int i = 0;

	for (Flight flight : auxBean.getFlights()) {
		if (i % 2 == 0) {
	bgColor = "#99CCFF";
		}
		else {
	bgColor = "#CCCCCC";
		}
%>
		<tr bgcolor= <%= bgColor %>>
		<td align="center"><%=(i+1)%>.</td>
		<td align="center"><a href='flight.jsp?flightid=<%=flight.getId()%>'><%=flight.getId()%></a></td>
		<td align="center"><%=flight.getDepartureTimeFormated()%></td>
		<td align="center"><%=flight.getArrivalTimeFormated()%></td>
		<td align="center"><%=flight.getSource()%></td>
		<td align="center"><%=flight.getDestination()%></td>
		<td align="center"><%=flight.getReservedSeatsCount()%></td>
		
<%
			if (DateTest.testDate(flight.getDepartureTime()) == false) {
		%>
		<form method="get" action="reservation.jsp">
			<td align="center">	
				<input type="hidden" name="flightid" value=<%= flight.getId() %>>
				<input type="submit" value="Reserve">
			</td>
		</form>
<%
	} else {
%>
	<td align="center">Expired</td>
<%
	}
%>
		
		</tr>
<%
	i++;
	}
%>		
</table>
<%
}
else {
%>
	Ne postoji nijedan let!<br />
<%
}
%>


<hr />
<p>
<a href="newflight.jsp">Add New Flight</a>
</p>
<p>
<a href="newcity.jsp">Add New City</a>
</p>
<p>
<a href="../LogoutServlet">Logout</a>
</p>


	
<jsp:include page="footer.jsp"></jsp:include>
		
</body></html>